package com.moyu.user.controller.user;

import com.moyu.common.core.controller.BaseController;
import com.moyu.common.core.domain.R;
import com.moyu.user.domain.user.User;
import com.moyu.user.domain.user.dto.UserRegDTO;
import com.moyu.user.service.user.IUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 普通用户控制类
 *
 * @Author 赵彦博
 * @Date 2024/12/20 10:37
 */
@RestController
@RequestMapping("/user")
@Tag(name = "普通用户接口")
public class UserController extends BaseController {

    @Autowired
    private IUserService userService;

    @GetMapping("/queryUserByAccount/{account}")
    @Operation(summary = "查询用户", description = "根据用户名查询用户")
    public R<User> queryUser(@PathVariable("account") String account) {
        User user = userService.query(account);
        return R.ok(user);
    }


    @PostMapping("/reg")
    @Operation(summary = "新增用户", description = "根据信息新增用户")
    public R<User> reg(@RequestBody UserRegDTO userRegDTO) {
        return userService.reg(userRegDTO);
    }

    @GetMapping("/sendEmailCode")
    @Operation(summary = "发送验证码", description = "发送验证码")
    public R sendEmailCode( @RequestParam(value = "emailAddress", required = false)  String emailAddress) {
        return userService.sendEmailCode(emailAddress);
    }


}
